package com.onec.service.api.dto.request.channel;


import com.onec.service.api.content.PatternUtil;
import com.onec.service.api.dto.request.BaseRequest;
import com.onec.service.api.dto.request.gateway.BizContent;
import com.onec.service.api.utils.group.MerchantModifyGroup;
import com.onec.service.api.utils.group.MerchantOpenGroup;
import com.onec.service.api.utils.group.MerchantRegisterGroup;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

/**
 * 请求通道服务！通道商户信息处理
 *
 * @author onec
 */
@Data
@EqualsAndHashCode(callSuper=false)
public class ChannelMerchantReq extends BaseRequest {


    /**
     * (机构)商户号
     */
    @NotNull(message = "商户编号不可为空", groups = {MerchantRegisterGroup.class})
    @Length(min = 5, max = 12, message = "商户编号介于5-12之间", groups = {MerchantRegisterGroup.class})
    public String outCode;
    /**
     * (机构)商户号
     */
    @NotNull(message = "商户编号不可为空", groups = {MerchantOpenGroup.class, MerchantModifyGroup.class})
    @Length(min = 5, max = 12, message = "商户编号介于5-12之间", groups = {MerchantOpenGroup.class})
    public String merchantNo;
    /**
     * (机构)商户简称
     */
    @NotNull(message = "商户名称不可为空", groups = {MerchantRegisterGroup.class})
    @Length(min = 5, max = 12, message = "商户名称介于5-12之间", groups = {MerchantRegisterGroup.class})
    public String merchantName;

    /**
     * 商户门店地址
     */
    @NotNull(message = "门店地址不可为空", groups = {MerchantRegisterGroup.class})
    @Length(min = 6, max = 20, message = "门店地址介于6-20之间", groups = {MerchantRegisterGroup.class})
    public String address;

    /**
     * 联行号
     */
    @NotNull(message = "联行号不可为空", groups = {MerchantRegisterGroup.class})
    public String bankCode;

    /**
     * 结算类型 :0对公，1对私
     */
    @NotEmpty(message = "结算类型格式有误", groups = {MerchantRegisterGroup.class})
    public String settleType;
    /**
     * 手机号
     */
    @NotNull(message = "手机号不可为空", groups = {MerchantRegisterGroup.class, MerchantModifyGroup.class})
    @Pattern(regexp = PatternUtil.PHONE, message = "手机信息不合法", groups = {MerchantRegisterGroup.class, MerchantModifyGroup.class})
    public String phone;

    /**
     * 结算卡
     */
    @NotNull(message = "结算卡号不可为空", groups = {MerchantRegisterGroup.class, MerchantModifyGroup.class})
    public String cardNo;
    /**
     * 姓名
     */
    @NotNull(message = "姓名不可为空", groups = {MerchantRegisterGroup.class})
    //@Pattern(regexp = PatternUtil.REG_NAME, message = "姓名格式有误", groups = {MerchantRegisterGroup.class})
    public String name;
    /**
     * 身份号
     */
    @NotNull(message = "身份证信息不可为空", groups = {MerchantRegisterGroup.class})
    @Pattern(regexp = PatternUtil.REG_ID_CARD,
            message = "身份信息不合法", groups = {MerchantRegisterGroup.class})
    public String idCard;
    /**
     *
     */
    @NotNull(message = "省编码不为空", groups = {MerchantRegisterGroup.class})
    public String province;
    /**
     *
     */
    @NotNull(message = "市编码不为空", groups = {MerchantRegisterGroup.class})
    public String city;
    /**
     * 身份号
     */
    @NotNull(message = "县编码不为空", groups = {MerchantRegisterGroup.class})
    public String country;

    /**
     * 通知地址：
     */
    @Pattern(regexp = PatternUtil.REG_URL, message = "回调地址URL不合法")
    public String callBackUrl;
    /**
     * 交易描述
     */
    public String message;
    /**
     * 代理编号
     */
    public String agentNo;
    /**
     * 代理编号
     */
    public String channelNo;

    @NotNull(message = "交易费率不可为空", groups = {MerchantOpenGroup.class})
    public String rate;

    @NotNull(message = "固定值不可为空", groups = {MerchantOpenGroup.class})
    public String fee;

    @NotNull(message = "产品名称不可空", groups = {MerchantOpenGroup.class})
    public String product;

    @NotNull(message = "业务编号不可为空", groups = {MerchantOpenGroup.class})
    public String businessNo;

    @NotNull(message = "通道业务编号不可为空", groups = {MerchantOpenGroup.class})
    public String channelBusinessNo;


    public ChannelMerchantReq(BizContent bizContent) {
        this.outCode = bizContent.getOutCode();
        this.merchantName = bizContent.getMerchantName();
        this.address = bizContent.getAddress();
        this.bankCode = bizContent.getBankCode();
        this.settleType = bizContent.getSettleType();
        this.phone = bizContent.getPhone();
        this.cardNo = bizContent.getCardNo();
        this.name = bizContent.getName();
        this.idCard = bizContent.getIdCard();
        this.province = bizContent.getProvince();
        this.city = bizContent.getCity();
        this.country = bizContent.getCountry();
        this.callBackUrl = bizContent.getCallBackUrl();

        this.agentNo = bizContent.getAgentNo();
        this.rate = bizContent.getRate();
        this.fee = bizContent.getFee();
        this.product = bizContent.getProduct();
        this.businessNo = bizContent.getBusinessNo();

    }

}
